package com.ziyucoding.springboot.labs.lab8.skywalking.dubbodemo.controller;

import com.ziyucoding.springboot.labs.lab8.skywalking.dubbodemo.api.UserServiceApi;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户 控制器
 *
 * @author ziyucoding
 * @date 2022-11-01
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Reference(protocol = "dubbo", version = "1.0.0")
    private UserServiceApi userServiceApi;

    @GetMapping("/findUserNameById")
    public Map<String, Object> findUserNameById(@RequestParam("id") Integer id) {
        String userName = userServiceApi.findUserNameById(id);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("msg", "成功");

        Map<String, Object> user = new HashMap<>();
        user.put("userName", userName);
        result.put("data", user);
        return result;
    }
}
